Week 3 Developer Data product exercise

library(plotly)
library(knitr)

Melanoma dataset

library(plotly)
library(knitr)
load(file="Melanoma.RData")
kable(Melanoma[1:5,], caption = "Melanoma table content")
Melanoma table content
time status sex age year thickness ulcer
10 3 1 76 1972 6.76 1
30 3 1 56 1968 0.65 0
35 2 1 41 1977 1.34 0
99 3 0 71 1968 2.90 0
185 1 1 52 1965 12.08 1

build linear model based on data for plotting

time<-Melanoma$time
status<-Melanoma$status

status<-as.factor(status) 

age<-Melanoma$age
thickness<-Melanoma$thickness
ulcer<-Melanoma$ulcer

model<-glm(ulcer~time+thickness,
           family = binomial(link = "logit"), data = Melanoma)

Update legend, axis labels and font

f <- list(
  family = "Arial, monospace",
  size = 18,
  color = "#7f7f7f"
)

x <- list(
  title = "Time",
  titlefont = f
)
y <- list(
  title = "Prediction of ulcer based on time and tickness",
  titlefont = f
)

Melanoma$sex <- factor(Melanoma$sex,
                    levels = c(0,1),
                    labels = c("female", "male"))

Plotting linear predictive model of ulcer as a function of time and tumor tickness

plot_ly(Melanoma, x = ~time, y = ~model, type = "scatter", mode = "lines", color = ~factor(sex)) %>%
  layout(xaxis = x, yaxis = y)